package com.text.day3_4.homework;


import java.util.*;

public class PukeCardUtils {

    // 声明扑克点数的数组
    public static final String[] POINTS_ARR = {"3","4","5","6","7","8","9","10","J","Q","K","A","2","SJOKER","BJOKER"};

    // 声明扑克花色的数组
    public static final String[] PUKE_TYPE = {"♥","♠","♦","♣"};


    /**
     * 模拟斗地主抓牌
     * @param cards  54张牌
     * @param p1  玩家1的手牌
     * @param p2
     * @param p3
     * @param d1  底牌，剩三张
     */
    public static void drawPukeCard(List<PukeCard> cards, List<PukeCard> p1, List<PukeCard> p2,
                                    List<PukeCard> p3, List<PukeCard> d1){
        Collections.shuffle(cards);
        for (int i = cards.size() - 1; i > cards.size() - 4; i--) {
            d1.add(cards.get(i));
        }
        List<PukeCard> cou = p1;
        for (int i = 0; i < cards.size() - 3; i++) {
            if (i == (cards.size() - 3)/3) cou = p2;
            if (i == (cards.size() - 3)/3*2) cou = p3;
            cou.add(cards.get(i));
        }


    }

    /**
     * 创建一副扑克牌
     * @return
     */
    public static List<PukeCard> createPukeList(){

        ArrayList<PukeCard> pukeCards = new ArrayList<>();
        for (int i = 0; i < POINTS_ARR.length-2; i++) {
            for (String type : PUKE_TYPE) {
                PukeCard pukeCard = new PukeCard(type, POINTS_ARR[i], i);
                pukeCards.add(pukeCard);
            }
        }
        // 单独处理大小王
        PukeCard sjoker = new PukeCard("", "SJOKER", 13);
        PukeCard bjoker = new PukeCard("", "BJOKER", 14);
        pukeCards.add(sjoker);
        pukeCards.add(bjoker);

        return pukeCards;
    }

    public static void main(String[] args) {
        List<PukeCard> pukeList = createPukeList();
//        for (com.text.day3_3.pockdemo.PukeCard pukeCard : pukeList) {
//            System.out.println(pukeCard);
//        }
//        System.out.println(pukeList.size());

        ArrayList<PukeCard> p1 = new ArrayList<>();
        ArrayList<PukeCard> p2 = new ArrayList<>();
        ArrayList<PukeCard> p3 = new ArrayList<>();
        ArrayList<PukeCard> d1 = new ArrayList<>();

        drawPukeCard(pukeList,p1,p2,p3,d1);

        p1.sort((o1, o2) -> o1.getValue() - o2.getValue());
        p2.sort((o1, o2) -> o1.getValue() - o2.getValue());
        p3.sort((o1, o2) -> o1.getValue() - o2.getValue());
        d1.sort((o1, o2) -> o1.getValue() - o2.getValue());

        System.out.println(p1 + "\t");
        System.out.println(p2 + "\t");
        System.out.println(p3 + "\t");
        System.out.println(d1 + "\t");

        zhaDan(p1);
        zhaDan(p2);
        zhaDan(p3);


    }

    public static void zhaDan (ArrayList<PukeCard> pukeCards) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        int count = 0;
        if (pukeCards.get(pukeCards.size() - 1).getValue() == 14 && pukeCards.get(pukeCards.size() - 2).getValue() == 13)
            count++;
        for (PukeCard pukeCard : pukeCards) {
            hashMap.put(pukeCard.getPoint(), hashMap.get(pukeCard.getPoint()) == null ? 1 : hashMap.get(pukeCard.getPoint()) + 1);
            if (hashMap.get(pukeCard.getPoint()) == 4)
                count++;
        }
        System.out.println(hashMap);
        System.out.println("炸弹数：" + count);    //王炸概率最高  ， 4个一样的很少
    }




}
